//
//  BackBoxPlanCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/30.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "BackBoxPlanCell.h"

@interface BackBoxPlanCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *tiCompanyTitleLab;
@property (nonatomic, strong) UILabel *tiCompanyLab;
@property (nonatomic, strong) UILabel *tiAddressTitleLab;
@property (nonatomic, strong) UILabel *tiAddressLab;
@property (nonatomic, strong) UILabel *lineLab;
@property (nonatomic, strong) UILabel *countTitleLab;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UIButton *addBtn;

@end

@implementation BackBoxPlanCell

+ (instancetype)BackBoxPlanCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"BackBoxPlanCell";
    BackBoxPlanCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[BackBoxPlanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.nameLab = [UILabel new];
        self.nameLab.textColor = HexColor(0x2B2C44);
        self.nameLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.nameLab];
        
        self.tiCompanyTitleLab = [UILabel new];
        self.tiCompanyTitleLab.textColor = HexColor(0x9C9DB3);
        self.tiCompanyTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.tiCompanyTitleLab];
        
        self.tiCompanyLab = [UILabel new];
        self.tiCompanyLab.textColor = HexColor(0x2B2C44);
        self.tiCompanyLab.font = [UIFont systemFontOfSize:14];
        self.tiCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.tiCompanyLab];
        
        self.tiAddressTitleLab = [UILabel new];
        self.tiAddressTitleLab.textColor = HexColor(0x9C9DB3);
        self.tiAddressTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.tiAddressTitleLab];
        
        self.tiAddressLab = [UILabel new];
        self.tiAddressLab.textColor = HexColor(0x2B2C44);
        self.tiAddressLab.font = [UIFont systemFontOfSize:14];
        self.tiAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.tiAddressLab];
        
        self.lineLab = [UILabel new];
        self.lineLab.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.lineLab];
        
        self.countTitleLab = [UILabel new];
        self.countTitleLab.textColor = HexColor(0x9C9DB3);
        self.countTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.countTitleLab];
        
        self.countLab = [UILabel new];
        self.countLab.textColor = HexColor(0x2B2C44);
        self.countLab.font = [UIFont systemFontOfSize:20];
        [self.bgView addSubview:self.countLab];
        
        self.addBtn = [UIButton new];
        [self.addBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.addBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.addBtn setTitle:@"新建返箱" forState:0];
        self.addBtn.backgroundColor = Color_ThemeColor;
        self.addBtn.layer.masksToBounds = YES;
        self.addBtn.layer.cornerRadius = 6;
        [self.addBtn addTarget:self action:@selector(addClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.addBtn];
    }
    return self;
}

- (void)addClick {
    if (self.newBlock) {
        self.newBlock();
    }
}

-(void)setModel:(BackBoxPlanModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 0;
    self.bgView.nim_width = ScreenW - 30;
    
    self.nameLab.text = self.model.company;
    [self.nameLab sizeToFit];
    self.nameLab.nim_left = 10;
    self.nameLab.nim_top = 15;
    self.nameLab.nim_width = self.bgView.nim_width - 20;
    
    self.tiCompanyTitleLab.text = @"提货单位：";
    [self.tiCompanyTitleLab sizeToFit];
    self.tiCompanyTitleLab.nim_left = self.nameLab.nim_left;
    self.tiCompanyTitleLab.nim_top = self.nameLab.nim_bottom + 10;
    
    self.tiCompanyLab.text = self.model.tiHuoCompany;
    self.tiCompanyLab.nim_left = self.tiCompanyTitleLab.nim_right;
    self.tiCompanyLab.nim_width = self.bgView.nim_width - 10 - self.tiCompanyLab.nim_left;
    self.tiCompanyLab.nim_top = self.tiCompanyTitleLab.nim_top;
    [self.tiCompanyLab sizeToFit];
    
    self.tiAddressTitleLab.text = @"提货地址：";
    [self.tiAddressTitleLab sizeToFit];
    self.tiAddressTitleLab.nim_left = self.nameLab.nim_left;
    self.tiAddressTitleLab.nim_top = self.tiCompanyLab.nim_bottom + 5;
    
    self.tiAddressLab.text = self.model.tiHuoAddress;
    self.tiAddressLab.nim_left = self.tiAddressTitleLab.nim_right;
    self.tiAddressLab.nim_width = self.bgView.nim_width - 10 - self.tiAddressLab.nim_left;
    self.tiAddressLab.nim_top = self.tiAddressTitleLab.nim_top;
    [self.tiAddressLab sizeToFit];
    
    self.lineLab.frame = CGRectMake(10, self.tiAddressLab.nim_bottom + 14, self.bgView.nim_width - 20, 1);
    
    self.countTitleLab.text = @"可回收箱子数：";
    [self.countTitleLab sizeToFit];
    self.countTitleLab.nim_left = 10;
    self.countTitleLab.nim_top = self.lineLab.nim_bottom + 22;
    
    self.countLab.text = [NSString stringWithFormat:@"%ld",(long)self.model.boxCount];
    [self.countLab sizeToFit];
    self.countLab.nim_left = self.countTitleLab.nim_right;
    self.countLab.nim_centerY = self.countTitleLab.nim_centerY;
    
    self.addBtn.frame = CGRectMake(self.bgView.nim_width - 20 - 90, self.lineLab.nim_bottom + 15, 90, 30);
    self.addBtn.nim_centerY = self.countLab.nim_centerY;
    
    self.bgView.nim_height = self.addBtn.nim_bottom + 15;
    
    self.height = self.bgView.nim_bottom + 10;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
